package com.doubleview.hutool;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.LineHandler;
import cn.hutool.core.text.csv.CsvReader;
import cn.hutool.core.text.csv.CsvUtil;

import java.io.File;
import java.nio.charset.Charset;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author huchengchao <huchengchao@kuaishou.com>
 * Created on 2021-12-24
 */
public class CsvUtils {

    public static void main(String[] args) {
        final CsvReader reader = CsvUtil.getReader();
        // 假设csv文件在classpath目录下

        final List<TestBean> result = reader.read(FileUtil.getReader(new File("/Users/huchengchao/Downloads/test.csv"), Charset.defaultCharset()), TestBean.class);
        result.forEach(testBean -> {
            System.out.println("brandId: " + testBean.getBrandId());
            System.out.println("bindAccountId: " + testBean.getBindAccountId());
        });


        FileUtil.readLines(new File(""), Charset.defaultCharset(), new LineHandler() {
            @Override
            public void handle(String line) {
                System.out.println(line);
            }
        });
    }

    private static class TestBean {
        private String policy;
        private String agreementNumber;
        private String brandName;
        private long brandId;
        private String masterAccountId;
        private long bindAccountId;
        private String remark;

        public String getPolicy() {
            return policy;
        }

        public void setPolicy(String policy) {
            this.policy = policy;
        }

        public String getAgreementNumber() {
            return agreementNumber;
        }

        public void setAgreementNumber(String agreementNumber) {
            this.agreementNumber = agreementNumber;
        }

        public String getBrandName() {
            return brandName;
        }

        public void setBrandName(String brandName) {
            this.brandName = brandName;
        }

        public long getBrandId() {
            return brandId;
        }

        public void setBrandId(long brandId) {
            this.brandId = brandId;
        }

        public String getMasterAccountId() {
            return masterAccountId;
        }

        public void setMasterAccountId(String masterAccountId) {
            this.masterAccountId = masterAccountId;
        }

        public long getBindAccountId() {
            return bindAccountId;
        }

        public void setBindAccountId(long bindAccountId) {
            this.bindAccountId = bindAccountId;
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }
    }
}
